#include <header.h>

pthread_mutex_t lock1;
pthread_mutex_t lock2;
void *run(void *arg){
	pthread_mutex_lock(&lock2);
	int res = pthread_mutex_trylock(&lock1);
	if(res != 0){
		printf("没有拿到\n");
		pthread_mutex_unlock(&lock2);
		return NULL;
	}

	printf("i am run\n");
	

	pthread_mutex_unlock(&lock1);
	pthread_mutex_unlock(&lock2);

	return NULL;
}


int main(int argc, char* argv[]){

	// 初始化锁,不设置锁的属性
	pthread_mutex_init(&lock1, NULL);
	pthread_mutex_init(&lock2, NULL);


	pthread_t son_id;
	pthread_create(&son_id, NULL, run, NULL);

	pthread_mutex_lock(&lock1);
	//sleep(1);
	pthread_mutex_lock(&lock2);

	printf("main\n");

	pthread_mutex_unlock(&lock2);
	pthread_mutex_unlock(&lock1);

	pthread_join(son_id, NULL);
	return 0;
}